package com.guoxin.concurrentprogramming.chapter3.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author guoxin
 * @date 2019/7/16
 */
public class ThreadPoolDemo {

    private static class MyTask extends Thread {
        @Override
        public void run() {
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName());
        }
    }

    public static void main(String[] args) {
        MyTask task = new MyTask();

        ExecutorService service = Executors.newFixedThreadPool(5);
//        ExecutorService service =  Executors.newCachedThreadPool();
//        for (int i = 0; i < 10; i++) {
//            service.submit(task);
//        }


        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
        scheduledExecutorService.schedule(task,5000,TimeUnit.MILLISECONDS);


    }
}
